<template>
  <div>
    <el-card style="min-width: 1200px">
      <el-button type="primary" icon="el-icon-link" @click="goAdd"
        >添加Webhooks</el-button
      >
      <el-table style="margin-top: 30px" :data="dataList">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="date"
          align="center"
          width="80"
          label="序号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.$index + 1 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="name"
          align="center"
          label="接收URL"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.urlAgreement + "://" }}{{ scope.row.notifyUrl }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="eventNames"
          align="center"
          label="通知事件"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="act"
          align="center"
          width="200"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text"
              >编辑</el-button
            >
            <el-button @click="handleTest(scope.row)" type="text"
              >测试</el-button
            >
            <el-button @click="deleteHandle(scope.row.id)" type="text"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import base64 from "@/utils/code";
import mixin from "@/mixins/mixin";
export default {
  name: "settingWebhooks",
  mixins: [mixin],
  data() {
    return {
      dataList: [],
      mixinViewModuleOptions: {
        getDataListURL: "/api/webhooks/pageWebhooks",
        deleteURL: "/api/webhooks/delete",
      },
      pageSize: 9999,
    };
  },
  watch: {
    "$store.state.testLine": {
      handler() {
        if(this.$route.name==this.$options.name){
          this.getDataList();
        }
      },
    },
    deep: true,
  },
  methods: {
    goAdd() {
      this.$router.push("/setting/addWebhooks");
    },
    handleClick(row) {
      this.$router.push({
        name: "settingWebhooksEdit",
        query: { item: base64.encode(JSON.stringify(row)) },
      });
    },
    handleTest(row) {
      this.$router.push({
        name: "settingWebhooksTest",
        query: { item: base64.encode(JSON.stringify(row)) },
      });
    },
  },
};
</script>

<style></style>
